package com.evildog.workspace.life.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.life.application.bo.WishBO;
import com.evildog.workspace.life.application.bo.WishListBO;
import com.evildog.workspace.life.application.bo.WishPageBO;
import com.evildog.workspace.life.application.convert.WishConvert;
import com.evildog.workspace.life.application.model.*;
import com.evildog.workspace.life.application.service.WishService;
import com.evildog.workspace.life.application.vo.WishListVO;
import com.evildog.workspace.life.application.vo.WishPageVO;
import com.evildog.workspace.life.application.vo.WishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * wish Controller
    愿望清单
 * </p>
 *
 * @author evildog
 * @since 2020-08-02
 */
@RestController
@RequestMapping("/wishes")
@AllArgsConstructor
@Api(tags = "wish相关接口")
public class WishController {

    private WishService wishService;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody WishParam wishParam) {
        return ResultGenerator.status(wishService.save(WishConvert.INSTANCE.convert(wishParam)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(wishService.removeById(id));
    }

    @PatchMapping("/{id}/status")
    @ApiOperation(value = "更新status接口")
    public Result<Boolean> updateStatus(@PathVariable("id") Long id, @RequestBody WishStatusParam wishParam) {
        return ResultGenerator.status(wishService.updateStatus(id, WishConvert.INSTANCE.convert(wishParam)));
    }

    @PatchMapping("/{id}/name")
    @ApiOperation(value = "更新name接口")
    public Result<Boolean> updateName(@PathVariable("id") Long id, @RequestBody WishNameParam wishParam) {
        return ResultGenerator.status(wishService.updateName(id, WishConvert.INSTANCE.convert(wishParam)));
    }

    @PatchMapping("/{id}/cost")
    @ApiOperation(value = "更新star接口")
    public Result<Boolean> updateCost(@PathVariable("id") Long id, @RequestBody WishCostParam wishParam) {
        return ResultGenerator.status(wishService.updateCost(id, WishConvert.INSTANCE.convert(wishParam)));
    }

    @PatchMapping("/{id}/star")
    @ApiOperation(value = "更新star接口")
    public Result<Boolean> updateStar(@PathVariable("id") Long id, @RequestBody WishStarParam wishParam) {
        return ResultGenerator.status(wishService.updateStar(id, WishConvert.INSTANCE.convert(wishParam)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<WishVO> getById(@PathVariable("id") Long id) {
        WishBO wishBO = wishService.getDetailById(id);
        return ResultGenerator.success(WishConvert.INSTANCE.convert(wishBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<WishPageVO>> getPageList(WishPageParam wishPageParam, PageQuery query){
        PagedResult<WishPageBO> wishPageBO = wishService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(wishPageParam),
                        WishConvert.INSTANCE.convert(wishPageParam));
        return ResultGenerator.success(WishConvert.INSTANCE.convert(wishPageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<WishListVO>> getList(WishListParam wishListParam){
        List<WishListBO> wishListBO = wishService.getList(
                        QueryConditionUtils.getQueryCondition(wishListParam),
                        WishConvert.INSTANCE.convert(wishListParam));
        return ResultGenerator.success(WishConvert.INSTANCE.convertVoList(wishListBO));
    }

}